package com.javatom.notes.api;

import com.javatom.notes.common.User;
import com.javatom.notes.common.model.BaseResponse;
import lombok.Data;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping(value = "/user")
@Slf4j
public class UserContrllor
{
    @Value("${server.port}")
    private String port;

    @RequestMapping(value = "/get")
    BaseResponse<User> get(@RequestBody User user){
        log.error("端口 {} ,请求一次 get {} ",port,user);
        return BaseResponse.success(User.createUser());
    }

    @RequestMapping(method = RequestMethod.GET, value = "/list")
    BaseResponse<List<User>> getList(){
        log.error("端口 {} ,请求一次 getList",port);
        List<User> list=new ArrayList<User>();
        list.add(User.createUser());
        list.add(User.createUser());
        return BaseResponse.success(list);
    }


    @RequestMapping(method = RequestMethod.POST, value = "/{userId}", consumes = "application/json")
    BaseResponse<User> update(@PathVariable("userId") Integer userId, User user){
        user.setId(userId);
        return BaseResponse.success(user);
    }
}
